﻿using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Zinnia.Extensions;
using Zinnia.Kernel;
using Zinnia.Kernel.Inject.Core;
using Zinnia.Lite.Core.Imp;
using Zinnia.Web.Common;

namespace Zinnia.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            KernelService.DependencyInjectHub.Init();
            var str = GetSyncHello().Result;
            Console.WriteLine(str);
            //Console.WriteLine(HttpHelper.GetUtf8("http://www.baidu.com"));
            while (true)
            {
                var isContinue = Console.ReadLine();
                if (isContinue.Equals("y", StringComparison.OrdinalIgnoreCase))
                    break;
                var data = JsonConvert.SerializeObject(new { name = "rain", age = 123 });
                Console.WriteLine("POST:" + HttpHelper.PostUtf8("http://test.zinnia.com/Request/Post", data.StrToUtf8Byte(), "application/json"));
                Console.WriteLine("AsyncPost:" + HttpHelper.PostUtf8("http://test.zinnia.com/Request/AsyncPost", data.StrToUtf8Byte(), "application/json"));
            }
            Console.WriteLine("ok");
            Console.Read();
        }

        public static async Task<string> GetSyncHello()
        {
            var str = await GetHello();
            return str;
        }

        public static Task<string> GetHello()
        {
            Task<string> t = Task.Run(() =>
            {
                return "Hello";
            });
            return t;
        }

    }
    /// <summary>
    /// 用户模型映射
    /// </summary>
    public class UserModelMap : ZinniaLiteIdentityMap<UserModel>
    {
        public UserModelMap() : base()
        {
        }
    }
    /// <summary>
    /// 内容管理系统用户[后台系统]
    /// </summary>
    public class UserModel : ZinniaBaseLite
    {
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 用户密码
        /// </summary>
        public string UserPassword { get; set; }
        /// <summary>
        /// 用户真实姓名
        /// </summary>
        public string UserRealName { get; set; }
        /// <summary>
        /// 用户别名
        /// </summary>
        public string UserAliasName { get; set; }
        /// <summary>
        /// 用户身份证号
        /// </summary>
        public string UserIDCard { get; set; }

        /// <summary>
        /// 用户手机号
        /// </summary>
        public string UserTel { get; set; }
        /// <summary>
        /// 用户家庭地址
        /// </summary>
        public string UserHomeAddress { get; set; }
        /// <summary>
        /// 用户家庭所在省
        /// </summary>
        public string Province { get; set; }
        /// <summary>
        /// 用户家庭所在市
        /// </summary>
        public string City { get; set; }
        /// <summary>
        /// 用户家庭所在县
        /// </summary>
        public string Country { get; set; }
        /// <summary>
        /// 用户家庭所在国家
        /// </summary>
        public string Nation { get; set; }
    }

    public interface ISayHello : IUintOfWorkDependencyInject
    {
        void Say();
        void OutputRefAddress(object obj);
    }

    public class SayHello : ISayHello
    {
        public void Say()
        {
            Console.WriteLine("Hello!");
        }

        public void OutputRefAddress(object obj)
        {
            Console.WriteLine(obj.GetHashCode());
        }
    }
}
